package com.flw.eslab.service.impl;

import java.io.File;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.flw.eslab.dao.ReportDao;
import com.flw.eslab.dto.PageInfo_Dto;
import com.flw.eslab.model.Project;
import com.flw.eslab.model.Report;
import com.flw.eslab.service.ReportManager;



//@Service("reportManager")
public class ReportManagerImpl implements ReportManager {
	@Resource
	private ReportDao reportDao;

	public ReportDao getReportDao() {
		return reportDao;
	}

	public void setReportDao(ReportDao reportDao) {
		this.reportDao = reportDao;
	}

	@Override
	public boolean add(Report report) {
		if(report.getContent()==null||report.getContent().equals("")){
			return false;
		}else{
			reportDao.save(report);
			return true;
		}
	}

	@Override
	public boolean delete(Report report) {
		if(report.getId()==null){
			report.setId(0);
		}
		if(reportDao.findById(Report.class, report.getId())==null||report.getContent()==null||report.getContent().equals(""))
		{
			return false;
		}else{
			reportDao.deleteById(Report.class, report.getId());
			return true;
		}

	}

	@Override
	public boolean modify(Report report) {
		if(report.getId()==null){
			report.setId(0);
		}
		if(reportDao.findById(Report.class, report.getId())==null||report.getContent()==null||report.getContent().equals(""))
		{
			return false;
		}else{
			reportDao.update(report);
			return true;
		}
	}

	@Override
	public File output() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PageInfo_Dto load(PageInfo_Dto pageInfo_Dto) {
		int pageNow=pageInfo_Dto.getPageNow()==null?1:pageInfo_Dto.getPageNow();
		int pageSize=pageInfo_Dto.getPagesize()==null?5:pageInfo_Dto.getPagesize();	
		return reportDao.findByPageInfo(Report.class, pageNow, pageSize, null, null);
	}
	
	
}
